$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/bplatformbeginnerarticletype/queryList',
        datatype: "json",
        colModel: [
			{ label: '公众号标识', name: 'gzhCode', index: 'gzh_code',align: "center", width: 80, hidden: true },
			{ label: '公众号', name: 'gzhName', index: 'gzh_name',align: "center", width: 80 },
			{ label: '标签ID', name: 'articleTypeId', index: 'article_type_id',align: "center", width: 50 },
			{ label: '标签名称', name: 'articleTypeName', index: 'articleTypeName',align: "center", width: 80 },
			{ label: '标签描述', name: 'articleTypeDesc', index: 'article_type_desc',align: "center", width: 80 },
			{ label: '排序', name: 'sort', index: 'sort',align: "center", width: 80 }, 			
			{ label: '展示数量', name: 'displayCount', index: 'display_count',align: "center", width: 80 },
			{ label: '创建时间', name: 'createTime', index: 'create_time',align: "center", width: 80 },
			{ label: '修改时间', name: 'modifyTime', index: 'modify_time',align: "center", width: 80 }, 			
			{ label: '操作', name: '', index: '',align: "center", width: 80, formatter: function (value,options,rowData) {
					let gzhCode = rowData["gzhCode"];
					let articleTypeId = rowData["articleTypeId"];
					//return "<a class='btn btn-primary' onclick='vm.update(\'"+gzhCode+"\',"+articleTypeId+")'>修改</a>";
					return '<a class="btn btn-primary" onclick="vm.update(\''+gzhCode+'\','+articleTypeId+')">修改</a>';
				}
			},
        ],
		viewrecords: true,
        height: 520,
        rowNum: 15,
		rowList : [15,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
		postData:{"gzhCode":vm.q.gzhCode,"articleTypeId":vm.q.articleTypeId,"name":vm.q.name},
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });

	$.ajax({
		type: "POST",
		async:false,
		url: baseURL + 'sys/buserinfo/getUserGzhList',
		contentType: "application/json",
		success: function(r){
			if(r.code==0){
				//vm.bbrandinfo=r.brandInfo;
				$("#selectUserGzhList").append(
					"<option value=''>全部平台</option>");
				for(var i=0;i<r.userGzhList.length;i++){
					$("#selectUserGzhList").append(
						"<option value=" + r.userGzhList[i].gzhCode +">"+ r.userGzhList[i].gzhName+"</option>");
					$("#gzhList").append(
						"<option value=" + r.userGzhList[i].gzhCode +">"+ r.userGzhList[i].gzhName+"</option>");
				}
			}
		}
	});
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		q: {
			gzhCode: '',
			articleTypeId: null,
			name: null
		},
		showList: true,
		title: null,
		bPlatformBeginnerArticleType: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		update: function (gzhCode, articleTypeId) {
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(gzhCode, articleTypeId)
		},
		saveOrUpdate: function (event) {
			var url = "sys/bplatformbeginnerarticletype/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.bPlatformBeginnerArticleType),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		getInfo: function(gzhCode, articleTypeId){
			let data = {gzhCode: gzhCode, articleTypeId: articleTypeId};
			$.get(baseURL + "sys/bplatformbeginnerarticletype/getInfo", data, function(r){
                vm.bPlatformBeginnerArticleType = r.bPlatformBeginnerArticleType;
            });

			/*$.ajax({
				type: GET,
				url:
			});*/
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
				postData:{"gzhCode":vm.q.gzhCode,"articleTypeId":vm.q.articleTypeId,"name":vm.q.name},
                page:page
            }).trigger("reloadGrid");
		}
	}
});